<?php

namespace app\admin\controller;

use app\admin\model\ArticleCategory;
use app\admin\model\ArticleList;
use app\admin\service\ArticleService;
use think\facade\Request;

class Article extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleList::getList());
        }
        $this->assign('categoryList', ArticleCategory::getCategoryAll());
        return $this->fetch();
    }

    // 添加
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleService::goAdd());
        }
        $this->assign('categoryList', ArticleCategory::getCategoryAll());
        return $this->fetch();
    }

    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleService::goEdit());
        }
        $data = ArticleList::find($id);
        $this->assign('data', $data);
        $this->assign('categoryList', ArticleCategory::getCategoryAll());
        return $this->fetch();
    }

    public function goStatus()
    {
        return $this->getJson(ArticleService::goStatus());
    }

    // 删除
    public function goRemove($id)
    {
        return $this->getJson(ArticleService::goRemove($id));
    }

    // 列表
    public function category()
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleCategory::getList());
        }
        return $this->fetch();
    }

    // 添加
    public function addCategory()
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleService::goAddCate());
        }
        return $this->fetch();
    }

    // 编辑
    public function editCategory($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(ArticleService::goEditCate());
        }
        $data = ArticleCategory::find($id);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function statusCategory()
    {
        return $this->getJson(ArticleService::goStatusCategory());
    }

    // 删除
    public function removeCategory($id)
    {
        return $this->getJson(ArticleService::goRemoveCate($id));
    }
}